package no.ffi.gismoidm.pubsub;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import no.ffi.gismoidm.idp.Config;

/**
 *
 * @author anders
 */
public class Test {
    
    public static void main(String[] args) throws Exception {
        
        
//        BooleanOperand b2 = new Or(new And(new GreaterThan(new AttributeOperand("WEIGHT"),new IntegerOperand(243)),
//                                            new NameExists(new AttributeOperand("OBSERVER"))),
//                                    new Equals(new AttributeOperand("Nationality"),new StringOperand("UK")));
//        System.out.println(b2);
//        
//        BooleanOperand b3 = new Or(
//                   new And(new GreaterThan("WEIGHT",243),
//                            new NameExists("OBSERVER")
//                          ),
//                   new Equals("Nationality","UK")
//                );
//        System.out.println(b3);
        
//        BooleanOperand bo = new And(new Startstring("ACCESS_ROLES","CLERK, OBSER"),
//                            new Equals("SEC_CLEARANCE","67"));
//        Properties prop = new Properties();
//        prop.setProperty("SEC_CLEARANCE", "67");
//        prop.setProperty("ACCESS_ROLES", "CLERK, OBSERVER, ACCOUNTANT");
//        BooleanValue bv = bo.getBooleanValue(prop);
//        System.out.println("Spørsmålet er: " + bo);
//        System.out.println("Svaret er:" + bv);
        
        if (args.length==0) Config.loadPropertiesFrom("/home/anders/config/mrouter1.properties");
        else Config.loadPropertiesFrom(args[0]);
        new ConnectionController();  // Setup outgoing connections
        new ConnectionListener(); // Setup incoming connections
    }
    
    public static void ymain(String[] args)throws Exception  {
        ServerSocket ss = new ServerSocket(4444);
        System.out.println("Accepting connections...");
        Socket s = ss.accept();
        System.out.println("Connection established");
        ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
        ObjectInputStream ois = new ObjectInputStream(s.getInputStream());
        System.out.println("Sending data...");
        while (true) {
            oos.writeObject(new String("Abcdef"));
            Thread.sleep(5000);
        }
    }
    
    
}
